name: Lint

on:
  push:
    branches: [ master, for-master ]
  pull_request:
    branches: [ master, for-master ]

jobs:
  lint-shell:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: "install tools"
        run: sudo apt-get -y -qq install shellcheck
      - name: "shellcheck"
        run: make verify

  check-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: "install tools"
        run: sudo apt-get -y -qq install scdoc
      - name: "make docs"
        run: make man

  check-commits:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: "Developer's Certificate of Origin"
        run: |
          echo
          echo 'Commits to check:'
          echo '${{ toJSON(github.event.commits) }}' | jq -r ".[].id" |
             xargs -r -i git log -1 --pretty='%H%x09%s%x09%ce%x09-%(trailers:key=Signed-off-by,valueonly,separator=%x00)' '{}' |
             tee /tmp/commits |
             cut -f1,2
          echo ''
          if grep -e '-$' /tmp/commits | cut -f1,2 | grep -e '^' > /tmp/bad-commits; then
             echo 'Сommits that fail verification:'
             cat /tmp/bad-commits
             echo ''
             echo 'The DCO Signoff Check for all commits has FAILED.'
             echo 'See https://github.com/legionus/libshell/blob/master/CONTRIBUTING.md'
             echo ''
             exit 1
          fi

  check-dash:
    runs-on: ubuntu-latest
    needs: [ lint-shell ]
    steps:
      - uses: actions/checkout@v2
      - name: "install tools"
        run: sudo apt-get -y -qq install dash
      - name: "unittests"
        run: make check CHECK_SHELL=/bin/dash V=1

  check-bash:
    runs-on: ubuntu-latest
    needs: [ lint-shell ]
    steps:
      - uses: actions/checkout@v2
      - name: "install tools"
        run: sudo apt-get -y -qq install bash
      - name: "unittests"
        run: make check CHECK_SHELL=/bin/bash V=1

  check-mksh:
    runs-on: ubuntu-latest
    needs: [ lint-shell ]
    steps:
      - uses: actions/checkout@v2
      - name: "install tools"
        run: sudo apt-get -y -qq install mksh
      - name: "unittests"
        run: make check CHECK_SHELL=/bin/mksh V=1
